// pages/saved_items/saved_items.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    opts: ["去店铺", "取消收藏"],
    saved_items: [
      { storeId: "001", goodId: "001001", goodName: "good1", savedNum: 4637, goodPrice: 2548.9, goodCoverImgUrl: "/images/sample_cate/1.jpeg" },
      { storeId: "001", goodId: "001001", goodName: "good1", savedNum: 4637, goodPrice: 2548.9, goodCoverImgUrl: "/images/sample_cate/1.jpeg" },
      { storeId: "001", goodId: "001001", goodName: "good1", savedNum: 4637, goodPrice: 2548.9, goodCoverImgUrl: "/images/sample_cate/1.jpeg" },
      { storeId: "001", goodId: "001001", goodName: "good1", savedNum: 4637, goodPrice: 2548.9, goodCoverImgUrl: "/images/sample_cate/1.jpeg" }
    ]
  },
  onLoad: function (e) {
    wx.showShareMenu({
      withShareTicket: true
    })

    /** 判断场景值，1044 为转发场景，包含shareTicket 参数 */
    if (e.scene == 1044) {
      wx.getShareInfo({
        shareTicket: e.shareTicket,
        success: function (res) {
          var encryptedData = res.encryptedData;
          var iv = res.iv;
        }
      })
    }

    console.log(e.shareTicket)
  },
  unsaved: function () {
    wx.showModal({
      title: '取消收藏',
      content: '点击确定取消收藏',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  chooseOpt: function (e) {
    console.log(e.detail.value);
    var opt = e.detail.value;
    var that = this;
    switch (opt) {
      case "0":
        break;
      case "1":
        console.log("delete")
        that.unsaved();
        break;
    }
  },
  onShareAppMessage: function () {
    return {
      title: '自定义转发标题',
      path: '/page/user?id=123',
      success: function (res) {
        var shareTickets = res.shareTickets;
        if (shareTickets.length == 0) {
          return false;
        }
        wx.getShareInfo({
          shareTicket: shareTickets[0],
          success: function (res) {
            var encryptedData = res.encryptedData;
            var iv = res.iv;
          }
        })
      },
      fail: function (res) {
        // 转发失败
      }
    }
  }
})